package com.pb.wkflow.api.controller;

import com.pb.infra.oth.entity.common.Result;
import com.pb.wkflow.api.controller.request.ClassifyQueryRequest;
import com.pb.wkflow.api.service.WfClassifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 流程分类
 * @author 苗益辉
 * @date 2022/9/8 10:27
 */
@Slf4j
@RestController
@RequestMapping("v1/workflow/classify")
public class ClassifyApi {

    /**
     * wfClassifyService
     */
    @Autowired
    private WfClassifyService wfClassifyService;

    /**
     * 分类查询
     * @param request request
     * @param pageIndex 页码
     * @param pageSize 页数
     * @return Result
     */
    @PostMapping("/list")
    public Result list(@RequestParam(value = "pageIndex") Integer pageIndex,
                        @RequestParam(value = "pageSize") Integer pageSize,
                        @RequestBody ClassifyQueryRequest request) {
        log.info("---------- 流程分类列表查询 ---------- {}", request);
        return wfClassifyService.list(request,pageIndex, pageSize);
    }

    /**
     * 保存分类
     * @param request request
     * @return Result
     */
    @PostMapping("save")
    public Result save(@RequestBody ClassifyQueryRequest request) {
        log.info("---------- 保存流程分类 ---------- {}", request);
        return wfClassifyService.save(request);
    }

    /**
     * 更新分类
     * @param request request
     * @return Result
     */
    @PostMapping("update")
    public Result update(@RequestBody ClassifyQueryRequest request) {
        log.info("---------- 更新流程分类 ---------- {}", request);
        return wfClassifyService.update(request);
    }

    /**
     * 获取可用的流程分类
     * @param isAble 是否可用
     * @return Result
     */
    @GetMapping("getAbleList")
    public Result getIsAble(@RequestParam(value = "isAble", required = false) Integer isAble) {
        log.info("---------- 获取可用的流程分类 ---------- {}", isAble);
        return wfClassifyService.getAbleList(isAble);
    }
}
